import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);
import vuexPer from "vuex-persistedstate";

export default new Vuex.Store({
  state: {
    list: [],
    color: "red",
  },
  getters: {},
  mutations: {
    add(state, title) {
      state.list.push({ title, time: new Date().toLocaleString(), status: 0 });
    },
    //添加的方法
    changeItem() {},
    changeStatus(state, obj) {
      let { index, status } = obj;
      //拿到下标和状态
      state.list[index].status = status;
    },
    //点击取消或者还原按钮
    changeColor(state) {
      let r = Math.floor(Math.random() * 256);
      let g = Math.floor(Math.random() * 256);
      let b = Math.floor(Math.random() * 256);
      state.color = `rgb(${r},${g},${b})`;
    },

    remove(state, index) {
      state.list.splice(index, 1);
    },
    //删除
    update(state, obj) {
      console.log(obj);
      state.list[obj.index].title = obj.value;
    },
    //更新
  },
  actions: {},
  modules: {},
  plugins: [vuexPer()],
});
